package tw.edu.tku.im.maze;
import org.json.JSONException;
import org.json.JSONObject;


public class AddRoomReqParser extends PacketParser {
   public static AddRoomReqParser INSTANCE = new AddRoomReqParser();
   
   private AddRoomReqParser() { }

   @Override
   public AddRoomReq parse(JSONObject jsonObj) throws JSONException {
      JSONObject parameter = jsonObj.getJSONObject("parameter");
      String room = parameter.getString("room");
      String homeowner = parameter.getString("homeowner");
      int ticket = parameter.getInt("ticket");
      int mapLv = parameter.getInt("mapLv");
      int mode = parameter.getInt("mode");
      if(parameter.isNull("roomPassword")) {
         return new AddRoomReq(room, homeowner, ticket, mapLv, mode);
      }
      else {
         String roomPassword = parameter.getString("roomPassword");
         return new AddRoomReq(room, homeowner, ticket, mapLv, mode, roomPassword);
      }
   }

   @Override
   public String acceptName() {
      return "addRoom";
   }


}
